local skel = fk.CreateSkill {
  name = "lb_zero__xiayu",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["lb_zero__xiayu"] = "狭驭",
  [":lb_zero__xiayu"] = "<b>锁定技</b>，出牌阶段开始时，你重铸两张牌，均为这些牌合法目标的角色本回合手牌对你可见且使用牌时弃置两张牌。",

  ["@[player_chara]lb_zero__xiayu-turn"] = "狭驭",
  ["#lb_zero__xiayu-recast"] = "狭驭：请选择两张牌重铸，重铸牌共同的合法目标本回合手牌对你可见且使用牌时弃置两张牌！",

  ["$lb_zero__xiayu1"] = "老席德！",
  ["$lb_zero__xiayu2"] = "下手稍微重点也没关系吧。",
  ["$lb_zero__xiayu3"] = "想做一次炮弹淋浴吗？满足你！",
}

skel:addEffect(fk.EventPhaseStart, {
  anim_type = "control",
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and player.phase == Player.Play and not player:isNude()
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local cids = player:getCardIds("he")
    if #player:getCardIds("he") > 2 then
      cids = room:askToCards(player, { min_num = 2, max_num = 2, include_equip = true, skill_name = skel.name, cancelable = false, prompt = "#lb_zero__xiayu-recast"})
    end
    if #cids > 0 then
      event:setCostData(self, {cards = cids})
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local cards = event:getCostData(self).cards
    if cards then
      room:recastCard(cards, player, skel.name)
      if player.dead then return end
      local list = {}
      for _, p in ipairs(room:getAlivePlayers()) do
        if table.contains(Fk:getCardById(cards[1]):getAvailableTargets(player), p) then
          table.insertIfNeed(list, p)
        end
      end
      if #cards == 2 then
        for _, p in ipairs(room:getAlivePlayers()) do
          if not table.contains(Fk:getCardById(cards[2]):getAvailableTargets(player), p) then
            table.removeOne(list, p)
          end
        end
      end
      if #list > 0 then
        room:setPlayerMark(player, "@[player_chara]lb_zero__xiayu-turn", table.map(list, Util.IdMapper))
      end
    end
  end,
})

skel:addEffect("visibility", {
  card_visible = function(self, player, card)
    local room = Fk:currentRoom()
    local to = room:getCardOwner(card.id)
    if to and player:hasSkill(skel.name) and table.contains(player:getTableMark("@[player_chara]lb_zero__xiayu-turn"), to.id)
    and table.contains(to:getCardIds("h"), card.id) then
      return true
    end
  end
})

skel:addEffect(fk.CardUsing, {
  anim_type = "negative",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and table.contains(player:getTableMark("@[player_chara]lb_zero__xiayu-turn"), target.id) and not target:isNude()
  end,
  on_use = function(self, event, target, player, data)
    player.room:askToDiscard(target, {
      min_num = 2,
      max_num = 2,
      include_equip = true,
      skill_name = skel.name,
      cancelable = false
    })
  end,
})

return skel
